﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace UT3Bots.UTItems
{
	public class UTPlayerScore : IComparable<UTPlayerScore>, INotifyPropertyChanged
	{

		//Private members
		private UTIdentifier _id;
		private string _name;
		private int _score;
		private DateTime _lastUpdated;


		#region Properties
		public UTIdentifier Id
		{
			get
			{
				return this._id;
			}
		}

		public string Name
		{
			get
			{
				return this._name;
			}
		}

		public int Score
		{
			get
			{
				return this._score;
			}
		}


		internal DateTime LastUpdated
		{
			get { return this._lastUpdated; }
		}
		#endregion



		internal UTPlayerScore(UTIdentifier Id, string Name, int Score)
		{
			this._id = Id;
			this._name = Name;
			this._score = Score;
		}


		internal void SetScore(int NewScore)
		{
			this._score = NewScore;
			this._lastUpdated = DateTime.Now;
			OnPropertyChanged("Score"); 
		}



		public override string ToString()
		{

			return this._id.ToString().PadRight(30) + " " + this._name.PadRight(30) + " " + this._score;
		}




		#region IComparable<UTPlayerScore> Members

		public int CompareTo(UTPlayerScore other)
		{
			if (this._score > other._score)
			{
				return -1;
			}
			else if (this._score < other._score)
			{
				return 1;
			}
			else
			{
				return this._id.CompareTo(other._id);
			}
		}

		#endregion



		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void OnPropertyChanged(string propName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propName));
		}

		#endregion
	}
}
